package com.zjy.software.day15;

class Producer implements Runnable {
  public static final int MAX = 10;
  private Account account;

  public Producer(Account account) {
    this.account = account;
   }

  @Override
  public void run() {

    while (true) {
      try {
        Thread.sleep( 900 );
       } catch (InterruptedException e) {
        e.printStackTrace();
       }
      synchronized (account) {
        if (account.getCount() <MAX) {
          account.setCount( account.getCount() + 2 );
          System.out.println( " =  生产了两个,剩余数量为" + account.getCount() );
          account.notify();
         } else {
          System.out.println("生产过剩,进入等待状态");
          try {
            account.wait();
           } catch (InterruptedException e) {
            e.printStackTrace();
           }
         }
       }
     }
   }
}

